package com.ikan.positionserver.util;

import com.google.common.collect.Lists;
import com.ikan.positionserver.dto.DeviceDto;
import com.ikan.positionserver.entity.Device;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
@Slf4j
@UtilityClass
public class DeviceConverter {
    public static final DeviceDto convert2Dto(Device device) {
        if (device == null) {
            return null;
        }
        DeviceDto deviceDto = new DeviceDto();
        deviceDto.setId(device.getId());
        deviceDto.setName(device.getName());
        deviceDto.setOutBandIp(device.getOutBandIp());
        deviceDto.setBizIp(device.getBizIp());
        deviceDto.setBizUsage(device.getBizUsage());
        deviceDto.setSeq(device.getSeq());
        deviceDto.setBrand(device.getBrand());
        deviceDto.setCcbSeries(device.getCcbSeries());
        deviceDto.setSeries(device.getSeries());
        deviceDto.setHeight(device.getHeight());
        deviceDto.setUStartId(device.getUStartId());
        deviceDto.setUEndId(device.getUEndId());
        deviceDto.setSn(device.getSn());
//        serverDto.setCreateTime(server.getCreateTime());
        deviceDto.setCreator(device.getCreator());
//        serverDto.setUpdateTime(server.getUpdateTime());
        deviceDto.setUpdator(device.getUpdator());
        deviceDto.setRackName(device.getRackName());
        deviceDto.setRackId(device.getRackId());
        return deviceDto;
    }

    public static final Device convert(DeviceDto deviceDto) {
        if (deviceDto == null) {
            return null;
        }
        Device device = new Device();
        device.setId(deviceDto.getId());
        device.setName(deviceDto.getName());
        device.setOutBandIp(deviceDto.getOutBandIp());
        device.setBizIp(deviceDto.getBizIp());
        device.setBizUsage(deviceDto.getBizUsage());
        device.setSeq(deviceDto.getSeq());
        device.setBrand(deviceDto.getBrand());
        device.setCcbSeries(deviceDto.getCcbSeries());
        device.setSeries(deviceDto.getSeries());
        device.setHeight(deviceDto.getHeight());
        device.setUStartId(deviceDto.getUStartId());
        device.setUEndId(deviceDto.getUEndId());
        device.setSn(deviceDto.getSn());
        device.setCreator(deviceDto.getCreator());
        device.setUpdator(deviceDto.getUpdator());
        device.setRackName(deviceDto.getRackName());
        device.setRackId(deviceDto.getRackId());
        return device;
    }

    public static final List<DeviceDto> convertDeviceList2Dto(List<Device> deviceList) {
        if (deviceList == null) {
            return null;
        }
        List<DeviceDto> deviceDtoList = Lists.newArrayList();
        for (Device rack : deviceList) {
            DeviceDto serverDto = convert2Dto(rack);
            deviceDtoList.add(serverDto);
        }
        return deviceDtoList;
    }
}
